$(function () {
    $("#iotCode").focus();
    var start=new Date();
    start.setHours(0);
    start.setMinutes(0);
    start.setSeconds(0);
    var end=new Date();
    end.setDate(end.getDate()+1);
    end.setHours(0);
    end.setMinutes(0);
    end.setSeconds(0);
    var start = {
        elem: '#startDate',
        type: 'datetime',
        value:start,
        min: '1900-01-01 00:00:00',
        max: '2099-06-16 23:59:59',
        isclear: true,
        istoday: true,
        choose: function (datas) {
            //end.min = datas; //开始日选好后，重置结束日的最小日期
            //end.start = datas //将结束日的初始值设定为开始日
        }
    };
    var end = {
        elem: '#endDate',
        type: 'datetime',
        value: end,
        min: '1900-01-01 00:00:00',
        max: '2099-06-16 23:59:59',
        isclear: true,
        istoday: true,
        choose: function (datas) {
            //end.min = datas; //开始日选好后，重置结束日的最小日期
            //end.start = datas //将结束日的初始值设定为开始日
        }
    };
    laydate.render(start);
    laydate.render(end);
    //渲染表格
    var columns = monitorList.columnsInit();
    var table = monitorList.gridInit(columns);
    var datas = monitorList.dataInit();
    $("#monitorTable").bootstrapTable("append",datas);
    //前一日
    $("#btn_qyr").on("click",function () {
        var start=new Date($("#startDate").val());
        start.setHours(0);
        start.setMinutes(0);
        start.setSeconds(0);
        start.setDate(start.getDate()-1);
        laydate.render({
            elem: '#startDate',
            type: 'datetime',
            value:start
        });
        var end=new Date($("#endDate").val());
        end.setHours(0);
        end.setMinutes(0);
        end.setSeconds(0);
        end.setDate(end.getDate()-1);
        laydate.render({
            elem: '#endDate',
            type: 'datetime',
            value:end
        });
    })
    //当日
    $("#btn_dr").on('click',function () {
        var start=new Date();
        start.setHours(0);
        start.setMinutes(0);
        start.setSeconds(0);
        laydate.render({
            elem: '#startDate',
            type: 'datetime',
            value: start
        });
        var end=new Date();
        end.setDate(end.getDate()+1);
        end.setHours(0);
        end.setMinutes(0);
        end.setSeconds(0);
        laydate.render({
            elem: '#endDate',
            type: 'datetime',
            value: end
        });
    })
    //后一日
    $("#btn_hyr").on('click',function () {
        var start=new Date($("#startDate").val());
        start.setHours(0);
        start.setMinutes(0);
        start.setSeconds(0);
        start.setDate(start.getDate()+1);
        laydate.render({
            elem: '#startDate',
            type: 'datetime',
            value: start
        });
        var end=new Date($("#endDate").val());
        end.setHours(0);
        end.setMinutes(0);
        end.setSeconds(0);
        end.setDate(end.getDate()+1);
        laydate.render({
            elem: '#endDate',
            type: 'datetime',
            value:end
        });
    })
    //前一时
    $("#btn_qys").on('click',function () {
        var start=new Date($("#startDate").val());
        start.setHours(start.getHours()-1);
        start.setMinutes(0);
        start.setSeconds(0);
        laydate.render({
            elem: '#startDate',
            type: 'datetime',
            value: start
        });
        var end=new Date($("#endDate").val());
        end.setHours(end.getHours()-1);
        end.setMinutes(0);
        end.setSeconds(0);
        laydate.render({
            elem: '#endDate',
            type: 'datetime',
            value:end
        });
    })
    //当时
    $("#btn_ds").on('click',function () {
        var start=new Date();
        start.setMinutes(0);
        start.setSeconds(0);
        laydate.render({
            elem: '#startDate',
            type: 'datetime',
            value: start
        });
        var end=new Date();
        end.setDate(end.getDate()+1);
        end.setMinutes(0);
        end.setSeconds(0);
        laydate.render({
            elem: '#endDate',
            type: 'datetime',
            value: end
        });
    })
    //后一时
    $("#btn_hys").on('click',function () {
        var start=new Date($("#startDate").val());
        start.setHours(start.getHours()+1);
        start.setMinutes(0);
        start.setSeconds(0);
        laydate.render({
            elem: '#startDate',
            type: 'datetime',
            value: start
        });
        var end=new Date($("#endDate").val());
        end.setHours(end.getHours()+1);
        end.setMinutes(0);
        end.setSeconds(0);
        laydate.render({
            elem: '#endDate',
            type: 'datetime',
            value: end
        });
    })
})
;(function(undefined) {
    "use strict"
    var _global;

    function result(args,fn){
        var argsArr = Array.prototype.slice.call(args);
        if(argsArr.length > 0){
            return argsArr.reduce(fn);
        } else {
            return 0;
        }
    }
    var monitorList = {
        columnsInit:function(){
            return  [{
                field: 'od',
                title: '序号',
                width:'2%',
                align:'center'
            }, {
                field: 'date',
                title: '时间',
                sortable : true
            }, {
                field: 'originalValue',
                title: '原始值',
                sortable : true
            }, {
                field: 'differenceValue',
                title: '差值'
            }, {
                field: 'calculatedValue',
                title: '计算值'
            }, {
                field: 'times',
                title: '次数'
            }]
        },
        gridInit:function(columns){
            return $("#monitorTable").bootstrapTable({
                url:'',
                columns: columns,
                striped: 'true',
                classes: 'table table-hover qxttable',
                pagination: 'true',
                pageNumber: 1,
                pageSize: 10,
                pageList: [
                    10, 30, 50, 100, 200
                ],
                onPostBody:function () {
                    $(".opt-dropdown").each(function(index,data){
                        var _this = this;
                        $(this).hover(function(){
                            $(_this).find(".opt-dropdown-menu").show();
                        },function(){
                            $(_this).find(".opt-dropdown-menu").hide();
                        })
                    });
                }
            })

        },
        dataInit:function(){
            return  [{
                od: 1,
                date:'2017-11-3 10:00:00',
                originalValue: 'DLC0001',
                differenceValue: 'DLC0001',
                calculatedValue: 'df',
                times:'23'
            }, {
                od: 2,
                date:'2017-11-3 10:00:00',
                originalValue: 'DLC0001',
                differenceValue: 'DLC0001',
                calculatedValue: 'df',
                times:'23'
            }]
        }
    }

    // 将插件对象暴露给全局对象
    _global = (function(){ return this || (0, eval)('this'); }());
    if (typeof module !== "undefined" && module.exports) {
        module.exports = monitorList;
    } else if (typeof define === "function" && define.amd) {
        define(function(){return monitorList;});
    } else {
        !('plugin' in _global) && (_global.monitorList = monitorList);
    }
}());